package com.zqh.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.ocean.rawsdk.ApiExecutor;
import com.alibaba.ocean.rawsdk.client.exception.OceanException;
import com.umeng.uapp.param.UmengUappGetAllAppDataParam;
import com.umeng.uapp.param.UmengUappGetAllAppDataResult;

public class StatisticsUtils {

     static private String appKey = "4703660";

     static private String secKey = "Z0PFFKcBYtP";

    /**
     * 获取app统计数据
     * @return
     */
    public static JSONObject umengUappGetAllAppData() {
        ApiExecutor apiExecutor = new ApiExecutor(appKey, secKey);
        apiExecutor.setServerHost("gateway.open.umeng.com");

        UmengUappGetAllAppDataParam param = new UmengUappGetAllAppDataParam();
        // 测试环境只支持http
        // param.getOceanRequestPolicy().setUseHttps(false);
        try {
            UmengUappGetAllAppDataResult result = apiExecutor.execute(param);
            System.out.print(result.getAllAppData());
            String jsonString = JSONObject.toJSONString(result);
            System.out.print(jsonString);
            JSONObject jsonObject =  (JSONObject) JSON.parseArray(JSONObject.parseObject(jsonString).getString("allAppData")).get(0);
            return jsonObject;
        } catch (OceanException e) {
            System.out.println("errorCode=" + e.getErrorCode() + ", errorMessage=" + e.getErrorMessage());
        }
        return null;
    }
//    public static void main(String[] args) {
//        StatisticsUtils statisticsUtils = new StatisticsUtils();
//        statisticsUtils.umengUappGetAllAppData();
//    }
}
